package com.aabte.springbootopenfeigndemo.core.bean;

import lombok.Data;
import lombok.ToString;

@Data
public class Response<T> {

    private String code;
    private String msg;
    private T data;

    public Response() {
    }

    public Response(String code, String msg, T data) {
        this.code = code;
        this.msg = msg;
        this.data = data;
    }

    public static <T> Response.ResponseBuilder<T> builder() {
        return new Response.ResponseBuilder<>();
    }

    @ToString
    public static class ResponseBuilder<T> {
        private String code = "ok";
        private String msg = "success";
        private T data;

        ResponseBuilder() {
        }

        public Response.ResponseBuilder<T> code(String code) {
            this.code = code;
            return this;
        }

        public Response.ResponseBuilder<T> msg(String msg) {
            this.msg = msg;
            return this;
        }

        public Response.ResponseBuilder<T> data(T data) {
            this.data = data;
            return this;
        }

        public Response<T> build() {
            return new Response<>(this.code, this.msg, this.data);
        }

    }
}
